package kr.re.kitri.io;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class FileReadNWrite {
	// file read
	public void fileRead(String fname){
		try {
			FileReader fr = new FileReader(fname);
			BufferedReader br = new BufferedReader(fr);
			StringBuffer sb = new StringBuffer();
			String str = "";
			
			while((str=br.readLine())!=null){
				sb.append(str+"\n");
			}
			str=sb.toString();
			System.out.println(str);
			br.close();
			fr.close();			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	// file write
	public void fileWrite(String fname, boolean append){
		try {
			FileWriter fw = new FileWriter(fname,append);
			PrintWriter pw = new PrintWriter(fw);
			BufferedReader br = 
				new BufferedReader(new InputStreamReader(System.in));
			String str="";
			
			while ((str=br.readLine())!=null) {
				pw.println(str);
				pw.flush();
			}
			pw.close();
			fw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
}








